package com.initialize.appapi.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.initialize.appapi.controller.model.AboutModel;
import com.initialize.appapi.controller.model.SiteInformationModel;
import com.initialize.appapi.service.SiteService;
import com.initialize.pub.mybatis.plus.entity.Site;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/3/15
 * Time: 5:54 下午
 * Description:
 */
@Api(tags = "站点API")
@RestController
@CrossOrigin
@RequestMapping(value = "/site")
public class SiteController {


    @Autowired
    SiteService siteService;

    @ApiOperation("获取大标题")
    @GetMapping("/headline")
    public R<Site> getBigTitle() {
        return R.ok(siteService.getById("SITE_TITLE"));
    }

    @ApiOperation("获取小标题")
    @GetMapping("/subtitle")
    public R<Site> getSubtitle() {
        return R.ok(siteService.getById("SITE_SUBHEADING"));
    }

    @ApiOperation("获取页脚")
    @GetMapping("/footer")
    public R<Site> getFooter() {
        return R.ok(siteService.getById("SITE_FOOTER_INFORMATION"));
    }

    @ApiOperation("获取关于")
    @GetMapping("/about")
    public R<Site> getAbout() {
        return R.ok(siteService.getById("SITE_ABOUT"));
    }

    @ApiOperation("保存站点信息")
    @PostMapping("/save_site_information")
    public R<String> saveSiteInformation(@RequestBody SiteInformationModel siteInformationModel) {
        siteService.update(Site.builder().key("SITE_TITLE").value(siteInformationModel.getSITE_TITLE()).build());
        siteService.update(Site.builder().key("SITE_FOOTER_INFORMATION").value(siteInformationModel.getSITE_FOOTER_INFORMATION()).build());
        siteService.update(Site.builder().key("SITE_SUBHEADING").value(siteInformationModel.getSITE_SUBHEADING()).build());
        return R.ok("over");
    }


    @ApiOperation("保存关于信息")
    @PostMapping("/about_information")
    public R<String> saveInformation(@RequestBody AboutModel aboutModel) {
        siteService.update(Site.builder().key("SITE_ABOUT").value(aboutModel.getSite_about()).build());
        return R.ok("over");
    }


}